package com.iknow.util;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.widget.Toast;

public class MsgDialog extends AlertDialog
{
  protected MsgDialog(Context paramContext)
  {
    super(paramContext);
  }

  public static void customProgress(ProgressRunnable paramProgressRunnable, ProgressHandler paramProgressHandler)
  {
    new ProgressThread(null, paramProgressRunnable, paramProgressHandler).start();
  }

  public static void showB2DeleteDialog(Context paramContext, DialogInterface.OnClickListener paramOnClickListener)
  {
    showB2Dilog(paramContext, 2131361798, paramOnClickListener);
  }

  public static void showB2Dilog(Context paramContext, int paramInt, DialogInterface.OnClickListener paramOnClickListener)
  {
    if (paramContext == null);
    while (true)
    {
      return;
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
      localBuilder.setTitle(2131361795);
      localBuilder.setMessage(paramInt);
      localBuilder.setPositiveButton(2131361796, paramOnClickListener);
      localBuilder.setNegativeButton(2131361797, paramOnClickListener);
      localBuilder.setCancelable(true);
      localBuilder.show();
    }
  }

  public static void showB2Dilog(Context paramContext, int paramInt, DialogInterface.OnClickListener paramOnClickListener, boolean paramBoolean)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setTitle(2131361795);
    localBuilder.setMessage(paramInt);
    localBuilder.setPositiveButton(2131361796, paramOnClickListener);
    localBuilder.setNegativeButton(2131361797, paramOnClickListener);
    localBuilder.setCancelable(paramBoolean);
    localBuilder.show();
  }

  public static void showB2Dilog(Context paramContext, String paramString, DialogInterface.OnClickListener paramOnClickListener)
  {
    if (paramContext == null);
    while (true)
    {
      return;
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
      localBuilder.setTitle(2131361795);
      localBuilder.setMessage(paramString);
      localBuilder.setPositiveButton(2131361796, paramOnClickListener);
      localBuilder.setNegativeButton(2131361797, paramOnClickListener);
      localBuilder.setCancelable(true);
      localBuilder.show();
    }
  }

  public static void showB2Dilog(Context paramContext, String paramString, DialogInterface.OnClickListener paramOnClickListener, boolean paramBoolean)
  {
    if (paramContext == null);
    while (true)
    {
      return;
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
      localBuilder.setTitle(2131361795);
      localBuilder.setMessage(paramString);
      localBuilder.setPositiveButton(2131361796, paramOnClickListener);
      localBuilder.setNegativeButton(2131361797, paramOnClickListener);
      localBuilder.setCancelable(paramBoolean);
      localBuilder.show();
    }
  }

  public static void showB2Dilog(Context paramContext, String paramString1, String paramString2, DialogInterface.OnClickListener paramOnClickListener, boolean paramBoolean, String paramString3, String paramString4)
  {
    if (paramContext == null);
    while (true)
    {
      return;
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
      localBuilder.setTitle(paramString1);
      localBuilder.setMessage(paramString2);
      localBuilder.setPositiveButton(paramString3, paramOnClickListener);
      localBuilder.setNegativeButton(paramString4, paramOnClickListener);
      localBuilder.setCancelable(paramBoolean);
      localBuilder.show();
    }
  }

  public static void showProgressDialog(Context paramContext, ProgressRunnable paramProgressRunnable, ProgressHandler paramProgressHandler)
  {
    ProgressDialog localProgressDialog = new ProgressDialog(paramContext);
    localProgressDialog.setCancelable(false);
    localProgressDialog.setMessage(paramContext.getResources().getString(2131361809));
    new ProgressThread(localProgressDialog, paramProgressRunnable, paramProgressHandler).start();
    try
    {
      localProgressDialog.show();
      return;
    }
    catch (Throwable localThrowable)
    {
      LogUtil.e(MsgDialog.class, localThrowable);
    }
  }

  public static void showToast(Context paramContext, int paramInt)
  {
    Toast.makeText(paramContext, paramInt, 0).show();
  }

  public static void showToast(Context paramContext, String paramString)
  {
    Toast.makeText(paramContext, paramString, 0).show();
  }

  public static abstract class ProgressHandler extends Handler
  {
    private ProgressDialog dialog = null;

    public void handleMessage(Message paramMessage)
    {
      handleMessage(paramMessage, this.dialog);
    }

    public abstract void handleMessage(Message paramMessage, ProgressDialog paramProgressDialog);
  }

  public static abstract interface ProgressRunnable
  {
    public abstract boolean runnable(Handler paramHandler);
  }

  protected static class ProgressThread extends HandlerThread
  {
    private ProgressDialog dialog;
    private MsgDialog.ProgressHandler handler;
    private MsgDialog.ProgressRunnable runnable;

    public ProgressThread(ProgressDialog paramProgressDialog, MsgDialog.ProgressRunnable paramProgressRunnable, MsgDialog.ProgressHandler paramProgressHandler)
    {
      super("ProgressThread");
      this.handler = paramProgressHandler;
      this.dialog = paramProgressDialog;
      this.runnable = paramProgressRunnable;
      MsgDialog.ProgressHandler.access$0(this.handler, paramProgressDialog);
    }

    public void run()
    {
      Looper.prepare();
      boolean bool = this.runnable.runnable(this.handler);
      if ((this.dialog != null) && (bool))
        this.dialog.dismiss();
    }
  }
}